package com.projet.map;

import java.util.HashMap;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Shape;

/**
 * The set of shapes supported for different tiles in the tiled environment
 * 
 * @author kevin
 */
public class TileShapes {
	/** The com.projet.map of names to shapes */
	public static final HashMap<String, Shape> shapes = new HashMap<String, Shape>();
	/** The shape for the standard block tile */
	public static final Polygon BLOCK;
	/*Declaration des polygon de collision en forme de triangle : 
	 * Dans l'ordre : triangle superieure droit, superieur gauche, inferieur droit, inferieur gauche */
	public static final Polygon triangleSd;
	public static final Polygon triangleSg;
	public static final Polygon triangleId;
	public static final Polygon triangleIg;
	
	static {
		BLOCK = new Polygon();
		BLOCK.addPoint(0,0);
		BLOCK.addPoint(1,0);
		BLOCK.addPoint(1,1);
		BLOCK.addPoint(0,1);
		shapes.put("BLOCK", BLOCK);
		triangleId = new Polygon();
		triangleId.addPoint(1,0);
		triangleId.addPoint(1,1);
		triangleId.addPoint(0,1);
		shapes.put("triangleId", triangleId);
		triangleIg = new Polygon();
		triangleIg.addPoint(0,0);
		triangleIg.addPoint(1,1);
		triangleIg.addPoint(0,1);
		shapes.put("triangleIg", triangleIg);
		triangleSd = new Polygon();
		triangleSd.addPoint(0,0);
		triangleSd.addPoint(1,0);
		triangleSd.addPoint(1,1);
		shapes.put("triangleSd", triangleSd);
		triangleSg = new Polygon();
		triangleSg.addPoint(0,0);
		triangleSg.addPoint(1,0);
		triangleSg.addPoint(0,1);
		shapes.put("triangleSg", triangleSg);
	}
	
	/**
	 * Get a piece of geometry by name specified in the tile XML
	 * 
	 * @param name The name of the geometry to retrieve
	 * @return The shape to represent the given tile type
	 * @throws SlickException Indicates a failure to locate the geometry for the given name
	 */
	public static Shape getShapeByName(String name) throws SlickException {
		Shape shape = shapes.get(name);
		if (shape == null) {
			shape = shapes.get("BLOCK");
			//throw new SlickException("Unrecognised shape: "+name);
			
		}
		
		return shape;
	}
}
